import sympy


def factor(num):
    t = []
    res = set()
    prime = 2
    while num != 1:
        while num % prime == 0:
            t.append(str(prime))
            num //= prime
        prime = sympy.nextprime(prime)
        if len(t) != 0:
            res.add(''.join(t))
        t = []
    return res


i = 635
while True:
    if i % 5000 == 0:
        print(i)
    s1 = factor(i)
    if len(s1) != 4:
        i += 1
        continue
    s2 = factor(i + 1)
    if len(s2) != 4:
        i += 2
        continue
    s3 = factor(i + 2)
    if len(s3) != 4:
        i += 3
        continue
    s4 = factor(i + 3)
    if len(s4) != 4:
        i += 4
        continue
    if len(s1 | s2 | s3 | s4) == 16:
        print(i)
        exit(0)
